package adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.List;

import bean.ZiLeiMuBean;


/**
 * 商城
 */
public class StoreAdapter extends BaseAdapter {
    List<ZiLeiMuBean> beanList;
    Context context;
    private int selectIndex;
    public StoreAdapter(List<ZiLeiMuBean> beanList, Context context, int selectIndex){
        this.beanList=beanList;
        this.context=context;
        this.selectIndex=selectIndex;
    }
    public void setIndex(int index){
        selectIndex = index;
    }
    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int position) {
        return beanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder;
        if(view==null){
            holder=new ViewHolder();
            view=LayoutInflater.from(context).inflate(R.layout.item_shangcheng,null);
            holder.include_text= (TextView) view.findViewById(R.id.include_text);
            holder.include_layout= (LinearLayout) view.findViewById(R.id.include_layout);

            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.include_text.setText(beanList.get(position).getName());
        if(position==selectIndex){
            holder.include_layout.setBackgroundResource(0);
        }else {
            holder.include_layout.setBackgroundResource(R.drawable.shape_shangpin);
        }

        return view;
    }
    class ViewHolder{
        LinearLayout include_layout;
        TextView include_text;
    }
}
